<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>

<body>
    <div id="app">
        <div>在文本框中不断输入字符，当按下enter时，显示前面已经输入的字符，同时清空文本框</div>
        {{msg}}
        <input type="text" name="name" id="input" v-on:keydown.space="keydown">
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: { msg: '' },
            methods: {
                keydown(e) {
                    console.log(e.keyCode);
                    this.msg = e.target.value;
                    e.target.value = '';
                }
            }
        })
    </script>
</body>

</html>